package model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.eclipse.persistence.jaxb.compiler.Generator;


@Entity
@Table(name="Persons")
public class Person {
	
	@Id
	@GeneratedValue
	private String id;
	private String firstName;
	private String lastName;
	private String initials;
	private boolean working = true;
	
	@ManyToOne
	private Department department;
	
	@OneToMany(mappedBy="person", cascade={CascadeType.ALL})
	private List<Manko> mankos = new ArrayList<Manko>();
	
	public Person(){
		
	}
	public Person(Department department, String firstName, String lastName, String initials){
		this.firstName = firstName;
		this.lastName = lastName;
		this.department = department;
		this.initials = initials;
	}
	
	//---------- Relations to Department

	public Department getDepartment() {
		return department;
	}
	void setDepartmentUD(Department department) {
		this.department = department;
	}
	
	public void setDepartment(Department department){
		if(department != null){
			this.setDepartmentUD(department);
			department.addPersonUD(this);
		}
		else{
			this.getDepartment().removePersonUD(this);
			this.setDepartmentUD(null);
		}
		
	}
// ------------ Relations to Manko
	
	public List<Manko> getAllMankos(){
		return new ArrayList<Manko>(mankos);
	}
	void addMankoUD(Manko manko){
		mankos.add(manko);
	}
	void removeMankoUD(Manko manko){
		mankos.remove(manko);
	}
	
	public void addManko(Manko manko){
		this.addMankoUD(manko);
		manko.setPersonUD(this);
	}
	public void removeManko(Manko manko){
		manko.setPersonUD(null);
		this.removeMankoUD(manko);
	}	
	
	//-------------- GET & SET
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getInitials() {
		return initials;
	}
	public void setInitials(String initials) {
		this.initials = initials;
	}
	public boolean isWorking() {
		return working;
	}
	public void setWorking(boolean working) {
		this.working = working;
	}
	
	
	
	
	
	

}
